home *** CD-ROM | disk | FTP | other *** search
/ The X-Philes (2nd Revision) / The X-Philes Number 1 (1995).iso / xphiles / coding / dsp / c5xug.exe / SQRT_OPT.ASM < prev    next >
Encoding:
Assembly Source File  |  1991-04-19  |  2.1 KB  |  67 lines

  1. ;**************************************************************
  2. ;  
  3. ;                 sqrt_opt.asm
  4. ;  
  5. ;                 staff
  6. ;  
  7. ;                 04-19-91
  8. ;  
  9. ;           (C) Texas Instruments Inc., 1992 
  10. ;  
  11. ;           Refer to the file 'license.txt' included with this 
  12. ;           this package for usage and license information. 
  13. ;  
  14. ;**************************************************************
  15. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  16. ;  Square Root Computation
  17. ;
  18. ;  This routine computes square root of a number that is located
  19. ;  in the lower half of accumulator. The number is in Q15 format.
  20. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  21.  
  22.  
  23. BRCR       .set    09h        ;DP=0
  24. ST0       .set    60h        ;Internal RAM block B2
  25. ST1        .set    61h
  26. NUMBER     .set    62h
  27. TEMPR      .set    63h
  28. GUESS      .set    64h
  29.  
  30.    .text
  31. SQRT   SST     #0,ST0
  32.        SST     #1,ST1        ;Save context
  33.        LDP     #0
  34.        SETC    SXM        ;Set SXM=1
  35.        SPM     1        ;Set PM mode for fractional arithmetic
  36.        SACL    NUMBER        ;Save the number
  37.        LACC    #0
  38.        SACB            ;Clear Accumulator Buffer
  39.        SPLK    #11,BRCR     ;initialize for 12 iterations
  40.        SPLK    #800h,GUESS    ;Set initial guess
  41.        LACC    NUMBER
  42.        SUB     #200h
  43.        BCNDD   LOOP,LT        ;If NUMBER<200h then begin looping
  44.        SPLK    #800h,TEMPR
  45.        LACC    #4000h        ;Otherwise set initial guess
  46.        SACL    GUESS        ;and temporary root to 4000h
  47.        SACL    TEMPR
  48.        SPLK    #14,BRCR     ;and increase iterations to 15
  49.  
  50. LOOP   RPTB    ENDLP-1        ;Repeat block
  51.        SQRA    TEMPR        ;Square temporary root
  52.        LACC    NUMBER,16
  53.        SPAC            ;Acc=NUMBER-TEMPR**2
  54.        NOP            ;Dead cycle for XC
  55.        XC      2,GT        ;If NUMBER>TEMPR**2 skip next 2 instr.
  56.        LACC    TEMPR,16
  57.        SACB            ;Otherwise ROOT <- TEMPR
  58.        LACC    GUESS,15
  59.        SACH    GUESS        ;GUESS <- GUESS/2
  60.        ADDB
  61.        SACH    TEMPR        ;TEMPR <- GUESS+ROOT
  62.  
  63. ENDLP  LACB            ;High Acc contains square root of NUMBER
  64.        RETD
  65.        LST     #0,ST0
  66.        LST     #1,ST1        ;Restore context
  67.